using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Windows.Forms;
using FBWMS;

namespace CommonClass
{

    /// <summary>
    /// Read Message for xml file
    /// author:michael
    /// date:2008/10/14
    /// </summary>
    public class G_CommonClassReadMessage
    {

        private static string _language;

        //public static string LanguageName
        //{
        //    get {
        //        return _language;
        //    }
        //    set {
        //        _language = value;
        //    }
        //}

        /// <summary>
        /// Get Message Description
        /// </summary>
        /// <param name="languagename">Language Name</param>
        /// <param name="keyname">Variable Key</param>
        /// <returns></returns>
        public static string G_ReadXmlMessage(string languagename, string keyname)
        {
            string Description = string.Empty;

            string filename = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\MessageDefine.xml";

            if (File.Exists(filename) == false)
            {
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, "not find MessageDefine.xml file", "G_CommonClassReadMessage.G_ReadXmlMessage");
                return Description;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            XmlNode node = doc.SelectSingleNode("//" + languagename + "/cd[@KeyName='" + keyname + "']/Description");

            if (node != null)
            {

                Description = node.InnerText;
            }
            else
            {
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, "not find  message of " + "/" + languagename + "/" + keyname, "G_CommonClassReadMessage.G_ReadXmlMessage");
            }


            return Description;
        }

        public static string G_ReadXmlMessage(string keyname)
        {
            _language = System.Globalization.CultureInfo.CurrentUICulture.ToString();
            return G_ReadXmlMessage(_language, keyname);
        }
    }
}
